import { useLocation } from "@tanstack/react-router";
import { useCallback } from "react";
export default function useMatchLocation() {
  const location = useLocation();
  const currentPath = location.pathname;
  
  // 判断当前路径是否匹配给定路径
  const isActive = useCallback(
    (path: string) => {
      return currentPath.startsWith(path);
    },
    [currentPath] // 监听currentPath变化，确保路径变化时函数能正确响应
  );
  
  return {
    isActive,
  };
}
